package com.bao.ad.advice;

import com.bao.ad.exception.AdException;
import com.bao.ad.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName GlobalExceptionAdvice
 *
 * @author Bai
 * @version 1.0
 * @date 2019/2/17 0017 下午 20:55
 **/
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handlerAdException(HttpServletRequest request,
                                                     AdException ex){
        CommonResponse<String> commonResponse = new CommonResponse<>(-1, "business error");
        commonResponse.setDate(ex.getMessage());
        return commonResponse;
    }
}
